package com.h3bpm.web.instance;

import com.alibaba.fastjson.JSONObject;
import com.h3bpm.web.common.utils.SqlUtil;
import com.h3bpm.web.instance.consultingOutcomeDocument.ConsultingOutController;
import data.DataRow;
import data.DataTable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**流程通用 controller
 * @author villwang
 * @date 2020/07/30
 **/
@RestController
@RequestMapping("/Portal/General")
public class GeneralController {
    private static final Logger logger = LoggerFactory.getLogger(GeneralController.class);

    @RequestMapping("/getUserName")
    public JSONObject getUserName(String objectId){
        logger.info("获取用户名称————————————————"+objectId);
        JSONObject result = new JSONObject();
        if(StringUtils.isNotBlank(objectId)){
            try {
                String sql="SELECT `Name` FROM ot_user WHERE ObjectID='" +objectId+"'";
                DataTable table = SqlUtil.doQuery(sql);
                List<DataRow> entityRows = table.getEntityRows();
                if(!entityRows.isEmpty()&&entityRows.size()>0) {
                    String Name= entityRows.get(0).getString("Name");
                    logger.info("获取用户名称————Name---"+Name);
                    result.put("state", "200");
                    result.put("data",Name);
                    return result;
                }

            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }
}
